<?php $this->pageTitle = 'Ticket # ' . $ticket->ticket_number; ?>
<div class="flat_area">
	<div class="grid_16 main-title no-border clearfix">
		<div class=" float-left">
			<h1 class="with-breadcrumbs">Ticket # <?php echo $ticket->ticket_number; ?></h1>	
			<div id="main-breadcrumbs">
				<?php
				$this->widget('zii.widgets.CBreadcrumbs', array(
					'homeLink' => false,
					'links' => array(
						'Tickets' => array('public/list', 'ticket_number' => $ticket->ticket_number, 'email' => $ticket->email, 'agency_id' => $this->agency->id),
						'#' . $ticket->ticket_number => array('public/view', 'ticket_number' => $ticket->ticket_number, 'email' => $ticket->email, 'agency_id' => $this->agency->id)
					)
				))
				?>
			</div>
		</div>
		<div class="controls float-left">
<!--			<a id="submitTicket" class="link-button with-icon" href="<?php echo $this->createUrl('public/update', array('id' => $ticket->id)); ?>">
				<img src="/images/icons/fugue/report--pencil.png" />
				Update Ticket
			</a>-->
		</div>	
    </div>
    <div class="grid_16 relative">
		<div class="section highlighted">
			<div class="block">
				<h4><strong><?php echo $ticket->subject; ?></strong></h4>
				<p>Added by <span class="blue"><?php echo $ticket->createdByUser->name; ?></span> about <span class="blue"><?php echo DateFormatter::ago($ticket->create_time); ?></span></p>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						array(
							'label' => 'Status',
							'value' => $ticket->current_status
						),
						array(
							'label' => 'Closed By',
							'value' => $ticket->closedByUser->name,
							'visible' => $ticket->isClosed()
						),
						array(
							'label' => 'Type',
							'name' => 'type'
						),
						array(
							'label' => $ticket->getReferenceLabel(),
							'name' => 'reference'
						),
						array(
							'label' => 'Create Date',
							'type' => 'raw',
							'value' => date("d-M-Y G:i:A", strtotime($ticket->create_time))
						),
						)));
				?>
				<?php
				$this->widget('zii.widgets.CDetailView', array(
					'data' => $ticket,
					'attributes' => array(
						'name',
						'email',
						'mobile',
						'source'
						)));
				?>
				<hr/>
				<strong>Description</strong><br/>
				<?php echo $ticket->summary; ?>
			</div>
		</div>
	</div>
	<div class="grid_10">
		<div class="section">
			<div class="block">
				<h2>Responses</h2>
				<div class="">
					<?php if (!empty($ticket->ticketResponses)): ?>
						<?php foreach ($ticket->ticketResponses as $ticketResponse): ?>
							<div class="ticket-response">
								<strong><?php echo date("d M, Y @ G:iA", strtotime($ticketResponse->response_time)); ?></strong> - <?php echo $ticketResponse->getRespondedByName(); ?><br/>
								<?php echo $ticketResponse->message; ?>
							</div>
						<?php endforeach; ?>
					<?php else: ?>
						<div>
							There are no responses to this ticket
						</div>
					<?php endif; ?>
				</div>
			</div>
		</div>
		<div class="section">
			<div class="block">
				<h2>Post Reply</h2>
				<?php
				$form = $this->beginWidget('CActiveForm', array(
					'id' => 'ticket-create-form',
					'enableAjaxValidation' => false,
						));
				?>
				<table class="form-table">
					<tr>
						<td>
							<?php echo $form->textArea($newTicketResponse, 'message', array('style' => 'width: 100%', 'rows' => '5', 'autocomplete' => 'off')); ?>
							<?php echo $form->error($newTicketResponse, 'message'); ?>
						</td>
					</tr>
				</table>
				<div class="row buttons">
					<?php echo CHtml::submitButton('Post Reply', array('class' => 'green')); ?>
					
					<?php if (!$ticket->isClosed()): ?>
						<?php echo CHtml::checkBox('alsoChangeStatus'); ?>
						Change status to:
						<?php echo $form->dropDownList($ticket, 'current_status', CHtml::listData(TicketStatusType::model()->findAllByAttributes(array('is_closing_status' => 1)), 'code', 'code')); ?>
					<?php endif; ?>
				</div>
				<?php $this->endWidget(); ?>
			</div>
		</div>
    </div>
	<div class="grid_6">
		<div class="section">
			<div class="block">
				<h2>Status History</h2>
				<div class="grid-view grey">
					<table class="items" width="100%">
						<?php if (!empty($ticket->ticketStatuses)): ?>
							<?php foreach ($ticket->ticketStatuses as $ticketStatus): ?>
								<tr>
									<td>
										<?php echo date("d M, Y @ G:iA", strtotime($ticketStatus->status_time)); ?>
									</td>
									<td>
										Set to <span class="blue"><strong><?php echo $ticketStatus->type; ?></strong></span> by <span class="blue link"><?php echo $ticketStatus->getUsername(); ?></span>
									</td>
								</tr>
							<?php endforeach; ?>
						<?php else: ?>
							<tr>
								<td>
									There are no responses to this ticket
								</td>
							</tr>
						<?php endif; ?>
					</table>
				</div>
			</div>
		</div>
		<?php if (!empty($ticket->escalations)): ?>
			<div class="section">
				<div class="block">
					<h2>Escalation History</h2>
					<div class="grid-view grey">
						<table class="items" width="100%">
							<?php foreach ($ticket->escalations as $escalation): ?>
								<tr>
									<td>
										<?php echo date("d M, Y @ G:iA", strtotime($escalation->escalation_time)); ?>
									</td>
									<td>
										<span class="blue">Escalated</span> to <span class="blue link"><?php echo $escalation->escalatedToUser->name; ?></span> <strong>(Level <?php echo $escalation->escalation_level; ?>)</strong>
									</td>
								</tr>
							<?php endforeach; ?>
						</table>
					</div>
				</div>
			</div>
		<?php endif; ?>
	</div>
</div>
